/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.config;

import cn.webrx.entity.Book;
import cn.webrx.servies.Db;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.*;

/**
 * <p>Project: spring2022 - SpringConfig
 * <p>Powered by webrx On 2022-03-18 09:10:07
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@Configuration("sc")
@ComponentScan({"cn.webrx.entity", "cn.webrx.servies"})
public class SpringConfig {

    @Bean @Lazy(false) @Scope("prototype")
    public Book java(){
        //System.out.println("实例化Book.........................");
        Book book = new Book();
        book.setId(10);
        book.setBookName("《java入门初步》");
        return book;
    }

    @Bean @Lazy(false)
    public Book python(){
        //System.out.println("实例化Book-py.........................");
        Book book = new Book();
        book.setId(22);
        book.setBookName("《python开发》");
        return book;
    }

    //@Bean
    //public Db db(@Qualifier("python") Book book){
    //自动装配，容器有python对象，如果要根据名称 @Qualifier("python") Book book
    public Db db(Book python){
        Db db = new Db();
        //db.setId(11);
        //db.setBook(python);
        return db;
    }

    @Bean(name = "db",initMethod = "a",destroyMethod = "a")
    public Db dbu(Book python){
        Db db = new Db(10);
        db.setId(88);
        db.setBook(python);
        return db;
    }
}
